//1、原型链式实现 弊端是所有实例共享father的引用 
//children.prototype.constructor 指向Father,需要手动更改为children 
function father(){
  this.name=[1,2,3]
  this.age=13
}
father.prototype.say=function(){
  console.log(123)
}
function children(){}
children.prototype=new father()
let child1=new children()
let child2=new children()
child1.name.push(4)
console.log(child1.name)
console.log(child2.name)

//2、构造函数继承  解决了所以实例都指向父实例的问题 、
//但是方法都在构造函数中定义，每次创建实例都会创建一遍方法。
function father(){
  this.arr=[1,2,3]
}
father.prototype.say=function(){
  console.log(123)
}
function children(){
  father.call(this)
}
let child1=new children()
let child2=new children()
child1.arr.push(4)
console.log(child1.arr)
console.log(child2.arr)

//3、原型链和构造函数组合起来的继承方式（即组合式继承）解决了上面两种方法的问题
//但是却调用了两次father的构造函数
function father() {
  this.arr = [1, 2, 3]
}
father.prototype.say = function () {
  console.log(123)
}
function children() {
  father.call(this)
}
children.prototype = new father()
children.prototype.constructor=children
children.prototype.speak=function(){
  console.log(123)
}
let child1 = new children()
let child2 = new children()
child1.speak()
child1.arr.push(4)
console.log(child1.arr)
console.log(child2.arr)

//4、原型式继承 临时创建一个构造函数，
//借助已有的对象作为临时构造函数的原型，然后在此基础实例化对象，并返回。
//本质上就是对对象的浅复制
function object(o) {
  function C() { }
  C.prototype = o
  return new C()
}
let children = {
  arr: [1, 2, 3]
}
let child1 = new object(children)
let child2 = new object(children)
console.log(child1.arr)

//5、寄生式继承 在上面原型式继承的继承上 再用了一个函数来增强对象 
//让其不仅拥有他人的属性和方法 也有自己的方法
function object(o) {
  function C() { }
  C.prototype = o
  return new C()
}
let children = {
  arr: [1, 2, 3]
}
function strong(o) {
  let strongChild = object(o)
  strongChild.sayHi = function () {
    console.log("hi")
  }
  return strongChild
}
let child1 = new strong(children)
let child2 = new strong(children)
console.log(child1.arr)
child1.sayHi()

//6、寄生组合式继承 （即寄生式和组合式一起用）
function object(o) {
  function F() {}
  F.prototype = o;
  return new F();
}
 
function prototype(child, parent) {
  var prototype = object(parent.prototype);
  prototype.constructor = child;
  child.prototype = prototype;
}
 
// 当我们使用的时候：
prototype(Child, Parent);

//7、ES6中通过class继承
class father{
  constructor(name,age){
    this.name=name
    this.age=age
  }
  say(){
    console.log(this.name)
  }
}
class children extends father{
  constructor(name,age,color){
    super(name,age)
    this.color=color
  }
  say(){
    return super.say()
  }
}
let child1=new children("jack",15,"blue")
console.log(child1.color)
child1.say()

//判断是否存在相同花色
function Judge(arr) {
  let result = []
  for (i = 0; i < arr.length; i++) {
    if (arr[i] <= 12) {
      result.push(1)
    }
    if (arr[i] > 12 && arr[i] <= 25) {
      result.push(2)
    }
    if (arr[i] > 25 && arr[i] <= 38) {
      result.push(3)
    }
    if (arr[i] > 38 && arr[i] <= 51) {
      result.push(4)
    }
  }
  let find = {}
  let j = 0
  while (j < result.length) {
    if (find[result[j]]) {
      find[result[j]]++
    }
    else {
      find[result[j]] = 1
    }
    j++
  }
  for (let k in find) {
    if (find[k] >= 5) {
      return true
    }
  }
  return false
}
console.log(Judge([0,2,4,5,6,7,8]))